new Vue({
    el: '#app',
    data() {
        return {
            ecode: '',
            epass: '',
            loginErrorMessage: '初始内容'
        }
    },
    created() {
        this.isLogin();
    },
    methods: {
        isLogin() {
            let _this = this;
            console.log('开始校验用户是否登陆')
            if (sessionStorage.getItem("b") !== "1") {
                axios.get('http://localhost:8031/emp/ecode/1', {
                    headers: {
                        token: localStorage.getItem("token")
                    }
                }).then((response) => {
                    console.log(response);
                    if (response.data.code !== 200) {
                        sessionStorage.setItem("b", "1");
                        location.href = '../login.html';
                    }
                })
            }
        },
        login() {
            let _this = this;
            axios.get('http://localhost:8031/emp/login', {
                params: {
                    username: _this.ecode,
                    password: _this.epass
                }
            }).then((response) => {
                // 接收返回结果
                let result = response.data;
                // 通过状态码来进行判断
                if (result.code === 200) {
                    // success
                    localStorage.setItem("token", result.data);
                    location.href = '../index.html';
                } else {
                    // failed
                    _this.loginErrorMessage = result.message;
                }
            })
        }
    }
});